package cn.tedu.springmvc.util;

public class JasonResult<T> {
    private Integer state; //业务返回码
    private String message;//消息
    private T data; //数据


    private JasonResult(){}


    public static  JasonResult<Void> ok(){
        return ok(null);

    }

    public static <T> JasonResult<T> ok(T data){
        JasonResult<T>  jasonResult = new JasonResult<>();
        jasonResult.state=State.OK.getValue();
        jasonResult.data=data;
        return jasonResult;

    }

    public static JasonResult<Void> fail(State state, String message){
        JasonResult<Void> jasonResult=new JasonResult<>();
        jasonResult.state = state.getValue();
        jasonResult.message =message;
        return jasonResult;
    }



    public enum State{
        OK(20000),
        ERR_USERNAME(40400),
        ERR_PASSWORD(40600);

        Integer value;
        State(Integer value){
            this.value=value;
        }

        public Integer getValue(){
            return value;
        }


    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public Integer getState() {
        return state;
    }

    public void setState(Integer state) {
        this.state = state;
    }
}
